package com.ruoyi.web.controller.cinema;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cinema.domain.FilmType;
import com.ruoyi.cinema.service.IFilmTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 影片类型Controller
 *
 * @author HHAOYU
 * @date 2020-12-12
 */
@RestController
@RequestMapping("/cinema/filmType")
public class FilmTypeController extends BaseController
{
    @Autowired
    private IFilmTypeService filmTypeService;

    /**
     * 查询影片类型列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:filmType:list')")
    @GetMapping("/list")
    public TableDataInfo list(FilmType filmType)
    {
        startPage();
        List<FilmType> list = filmTypeService.selectFilmTypeList(filmType);
        return getDataTable(list);
    }

    /**
     * 导出影片类型列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:filmType:export')")
    @Log(title = "影片类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FilmType filmType)
    {
        List<FilmType> list = filmTypeService.selectFilmTypeList(filmType);
        ExcelUtil<FilmType> util = new ExcelUtil<FilmType>(FilmType.class);
        return util.exportExcel(list, "filmType");
    }

    /**
     * 获取影片类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('cinema:filmType:query')")
    @GetMapping(value = "/{filmCode}")
    public AjaxResult getInfo(@PathVariable("filmCode") String filmCode)
    {
        return AjaxResult.success(filmTypeService.selectFilmTypeById(filmCode));
    }

    /**
     * 新增影片类型
     */
    @PreAuthorize("@ss.hasPermi('cinema:filmType:add')")
    @Log(title = "影片类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FilmType filmType)
    {
        return toAjax(filmTypeService.insertFilmType(filmType));
    }

    /**
     * 修改影片类型
     */
    @PreAuthorize("@ss.hasPermi('cinema:filmType:edit')")
    @Log(title = "影片类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FilmType filmType)
    {
        return toAjax(filmTypeService.updateFilmType(filmType));
    }

    /**
     * 删除影片类型
     */
    @PreAuthorize("@ss.hasPermi('cinema:filmType:remove')")
    @Log(title = "影片类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{filmCodes}")
    public AjaxResult remove(@PathVariable String[] filmCodes)
    {
        return toAjax(filmTypeService.deleteFilmTypeByIds(filmCodes));
    }
}
